#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 17 17:56:47 2022

A test for OLE_linprog program.

@author: zq
"""

import numpy as np
from OLE_linprog import OLE_linprog
import matplotlib.pyplot as plt

m, n = 256, 128
# 256x128矩阵，每个元素服从Gauss随机分布
A = np.random.randn(m, n)
# 128x1矩阵，每个元素服从Gauss随机分布
# b = A * u, 则 Au - b = 0，u 即为我们要求的精确解
u = np.random.randn(n, 1)
b = np.dot(A, u)
alpha = OLE_linprog(A, b)
# 恢复残差 
print('\n恢复残差：', np.linalg.norm(alpha - u, 2))
# 绘图
plt.figure(figsize = (8, 6))
# 绘制原信号
plt.plot(u, 'b', linewidth = 2, label = 'Original')
# 绘制恢复信号
plt.plot(alpha, 'r.-', linewidth = 2, label = 'Recovery')
plt.grid() 
plt.legend()
plt.show()